import os
import multiprocessing

root='D:\lijiguo\JEM_test';

def encode(cfg, QP, anchor_test):
    name = os.path.split(cfg)[1]
    if len(name)<8:
	    return;
    name=name[8:];
    print(name);
    command = "{3}/JEM_with_360lib/bin/TAppEncoder_{4}.exe -c  {3}/cfg/cfg/encoder_randomaccess_jvet10.cfg -c {3}/cfg/cfg-360Lib/encoder_360_ERP.cfg -c {0} --SphFile={3}/cfg/cfg-360Lib/360Lib/sphere_655362.txt --CodingFaceWidth=3072 --CodingFaceHeight=1536 --IntraPeriod=32 -b {3}/str/{1}_{2}_{4}.bin  --SEIDecodedPictureHash=1 -o {3}/rec/{1}_3072x1536_10bit_rec_{2}_{4}.yuv  -q {2} -f 32>>{3}/log/{1}_{2}_{4}.log".format(cfg, name[:-4], QP, root, anchor_test);
    print(command);
    os.system(command);


if __name__ == "__main__":
    per_cfg_root = r"../per_sequence/"#cfg-360Lib/per-sequence/360/

    pool = multiprocessing.Pool(processes=8)

    for i_cfg in os.listdir(per_cfg_root):
        print(i_cfg);
        if i_cfg[-4:] != ".cfg":
            continue;
        for QP in [22, 27, 32, 37]:
            pool.apply_async(func=encode, args=(os.path.join(per_cfg_root, i_cfg), QP, "anchor"))
            pool.apply_async(func=encode, args=(os.path.join(per_cfg_root, i_cfg), QP, "test"))

    pool.close()
    pool.join()
	
